<?php
class SearchApp extends CommonApp {
   
    //搜索
    public function indexAct(){
        $where = "publish=1 AND `item` IN ('news','announ','game','chair','project','country','province','event','team','download')";
        $keyword = I('get.keyword');
        if($keyword!='')
            $where.=" AND title LIKE '%{$keyword}%'";
        $this->assign('keyword',$keyword);
        $total = DB('datas')->where($where)->cache()->count();
        $result['page'] = My::page($total,array('pagesize'=>10));
        //数据
        $result['data'] = DB('datas')->where($where)->limit($result['page']['limits'])->order('adddate DESC,id DESC')->cache()->select();
        if(is_array($result['data']))
        foreach($result['data'] as &$value){
            //去掉html标签
            $value['content'] = trim(strip_tags(My::decodeHtml($value['content'])));
            //截取前150个字符
            $value['desc'] = mb_substr($value['content'], 0,150,'utf-8');
            $value['params'] = My::decodeJson($value['params']);
            if ($value['item'] == 'download')
                $value['params']['files'] = str_replace('/', '-', $value['params']['files']);
        }
        $this->assign('result',$result);
    	//display
		$this->display('Common/search',$_GET);
    }
    //搜索
    public function detailAct(){
        $id = I('get.id');
        if(!My::is_id($id))
            $this->ajaxReturn(404,'文章详情ID有误误!');
        // $item = My::arr2var($_REQUEST,'item');
        $result = self::detail($id);
        $this->assign('result',$result);
        $this->assign('menu',self::menu($result['item']));
        $this->display('Common/detail');
    }
   
}